<?php

/**
  彩票信息模块 
 */

namespace McWin\Controller;
use Common\Controller\HomebaseController;
// load("@.myfunc");

class NmgK3Controller extends HomebaseController {

	function _initialize(){}

	/**
	 *  读取赔率数据.
	 *	nmg_k3: 内蒙古快3
	 *  bj_cars: 北京赛车
	 *
	 */		

	/**
	 * @return 内蒙古K3 发送开奖信息.
	 */
	public function sendOpen(){		
		$data['type'] = 'nmg_k3';

		// 最新开奖期数
		$D = D('NmgK3Open');
		$qishu_pre = $D -> read_open();
		$data['qishu_pre'] = $qishu_pre;

		// 计算新的期数。
		$qishu['qihao'] = $this -> qihao_cal( $qishu_pre['qihao'] );
		// $lottery_time = time()+1*12*3600;
		$lottery_time = time();
		$resttime = strtotime($qishu_pre['time']) + 600 - $lottery_time;
		$qishu['resttime'] = $resttime;
		$data['qishu'] = $qishu;
		
		$this->return_data($data);		
	}

	/**
	 * @param  计算期数号, 根据上期号， 计算本期号。
	 * @return [type]
	 */
	private function qihao_cal($qihao_pre){
		$qihao = substr($qihao_pre,0,-3) . str_pad(intval(substr($qihao_pre,-3)) + 1, 3, '0', STR_PAD_LEFT);
		// $qihao = substr($qihao_pre,0,-3) . substr($qihao_pre,-3);
		return $qihao;
	}

	/**
	 * 发送赔率和投注上限信息.
	 * @return [type]
	 */
	public function sendOdds(){		
		// 加上彩种
		$data['type'] = 'nmg_k3';

		// 赔率
		$D = D('NmgK3Odds');
		$odds = $D -> get_odds();
		if($odds)
			$data['odds'] = $odds;
		
		// 投注上限
		$D = D('NmgK3UpLimit');
		$upLimit = $D -> get_Up_Limit();
		if($upLimit)
			$data['upLimit'] = $upLimit;
		
		$this->return_data($data);	
	}
	
}